package ysw.action;

import static com.opensymphony.xwork2.Action.NONE;
import static com.opensymphony.xwork2.Action.SUCCESS;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import ysw.jdbc.MessageJdbc;
import ysw.vo.Message;

public class MessageAction extends ActionSupport{
	private Message message;

    public Message getMessage() {
        return message;
    }

    public void setMessage(Message message) {
        this.message = message;
    }

   
 
    private List<Message> messageList;
    public String execute() throws Exception{
        MessageJdbc messageJ=new MessageJdbc();
        message.setCid(message.getCid());
        message.setCname(message.getCname());
        message.setMtime(message.getMtime());
        message.setContent(message.getContent());
  
            
     
       messageJ.addMessage(message);
        return SUCCESS;
    }
    

public String showAllMessage(){
     
	   Message message=new Message();
           MessageJdbc messageJ=new MessageJdbc();
 
        try{
            messageList=messageJ.showMessage();
        }catch(SQLException e){
            e.printStackTrace();
        }
     
		Map request=(Map)ActionContext.getContext().get("request");
        request.put("messageList",messageList);
        return SUCCESS;
    }

public String showOneMessage() throws Exception{
    Message message1=new Message();
           MessageJdbc messageJ=new MessageJdbc();
    message1=messageJ.showOneMessage(message.getId());
Map request=(Map)ActionContext.getContext().get("request");
request.put("message1",message1);
return SUCCESS;
}

public String updateSaveMessage() throws Exception{
      MessageJdbc messageJ=new MessageJdbc();
       message.setId(message.getId());
        message.setCid(message.getCid());
        message.setCname(message.getCname());
        message.setMtime(message.getMtime());
        message.setContent(message.getContent());
        message.setAnswer(message.getAnswer());
     
            messageJ.updateSaveMessage(message);
    return SUCCESS;
}

}
